// pages/goumai2/goumai2.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gouwulist:[],
    yue:"",
    ri:"",
    shi:"",
    fen:"",
    miao:"",
    zhou:"",
    str:"",
    pass: 123456,
    showPayPwdInput: false, //是否展示密码输入层
    pwdVal: '', //输入的密码
    payFocus: true, //文本框焦点
    dizhi:[],
    dizhiinfo:{},
    code1:{},
    code2:{},
    code3:{},
    dblo:false
  },
  showInputLayer() {
    this.setData({
      showPayPwdInput: true,
      payFocus: true
    });
  },
  hidePayLayer() {
    this.setData({
      showPayPwdInput: false,
      payFocus: false
    });


  },
  /**
   * 获取焦点
   */
  getFocus() {
    this.setData({
      payFocus: true
    });
  },
  /**
   * 输入密码监听
   */
  inputPwd(e) {
    this.setData({
      pwdVal: e.detail.value
    });
    console.log(e);
    if (e.detail.value.length >= 6) {
        /**获取输入的密码**/
      var val = this.data.pwdVal;
    if (val != this.data.pass) {
      this.setData({
        showPayPwdInput: false,
        payFocus: false,
        pwdVal: '',
        blo:false
      }, function () {
        /**弹框**/
        wx.showToast({
          title: `密码错误`
        })
      });
    } else if (val == this.data.pass) {
      this.setData({
        showPayPwdInput: false,
        payFocus: false,
        pwdVal: '',
        blo:true
      }, function () {
        /**弹框**/
        wx.showToast({
          title: `支付成功`,
        })
        
        let fu = wx.getStorageSync('fu')
        wx.setStorageSync('carts', fu)
        let shouhuo = wx.getStorageSync('shouhuo') || []
        // let index = shouhuo.findIndex((v)=>v.goods_id==this.data.gouwulist.goods_id)
        for(var i =0;i<this.data.gouwulist.length;i++){
          shouhuo.push(this.data.gouwulist[i]) 
        }
        wx.setStorageSync('shouhuo', shouhuo.reverse())
        wx.setStorageSync('shouhuo2', shouhuo)
      });
      
    }
      this.hidePayLayer();
    }
  },
  jiesuan() {
    let blo = wx.getStorageSync('dizhiinfo',blo)||[]
    if(this.data.str>0){
      if(blo.blo==true||blo==[]){
        this.showInputLayer();
      }else{
        wx.showToast({
          title: '请填写收货地址',
          icon:'none'
        })
      }
    }
      
    

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let pages = getCurrentPages();
    let currentPage = pages[pages.length - 1];
    let {
      a
    } = currentPage.options
    let list = wx.getStorageSync('onelist')
    let dizhi = wx.getStorageSync('dizhi')
    let dizhiinfo= wx.getStorageSync('dizhiinfo')
    this.setData({
      code1:dizhi[0],
      code2:dizhi[1],
      code3:dizhi[2],
      dizhiinfo
    })
    let time = new Date()
    let yue =time.getMonth()+1
    let ri = time.getDate()+1
    let shi =time.getHours()
    let fen = time.getMinutes()
    let miao = time.getSeconds()
    let zhou = time.getDay()+1
    console.log(`${yue}月${ri}日[周${zhou}]${shi}:${fen}`);
    let gouwulist = wx.getStorageSync('jiesuan')
    let str = 0
    gouwulist.map((item)=>{
      str +=item.num*item.goods_price
    })
    this.setData({ 
      str,
      gouwulist,
      yue,
      ri,
      shi,
      fen,
      miao,
      zhou
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    console.log(1);
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})